package com.dongjiantong.biz.serviceImpl;

import com.alibaba.dubbo.config.annotation.Service;
import com.dongjiantong.biz.mapper.DrugStoreMapper;
import com.dongjiantong.biz.model.DrugStore;
import com.dongjiantong.biz.service.DrugStoreService;
import com.dongjiantong.mybatis.ServiceMybatis;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.google.common.base.Strings;
import com.google.common.collect.Maps;
import lombok.extern.slf4j.Slf4j;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * Created by ThinkPad on 2017/12/11.
 */
@Slf4j
@Service(version = "1.0.0")
public class DrugStoreServiceImpl extends ServiceMybatis<DrugStore> implements DrugStoreService{
    @Resource
    private DrugStoreMapper drugStoreMapper;

    /**
     * 根据类型查询兽药库
     * @param type
     * @param group
     * @return
     */
    @Override
    public List<DrugStore> SelectByType(Integer type, Integer group) {

        DrugStore drugStore =new DrugStore();
        drugStore.setType(type);
        drugStore.setGroup_type(group);

        return drugStoreMapper.select(drugStore);
    }

    /**
     * 疫苗的列表 (包含code和name)
     * @return List<Map<String,Object>>
     */
    @Override
    public List<Map<String, Object>> selectVaccineList(Map<String, Object> map) {
        return drugStoreMapper.selectVaccineList(map);
    }

    /**
     * 分页查询药品库
     */
    @Override
    public PageInfo<Map<String,Object>> getDrugStore(Integer type, String name, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize);

        Map<String,Object> map = Maps.newHashMap();

        if (type != null) {
            map.put("type",type);
        }
        if (!Strings.isNullOrEmpty(name)) {
            map.put("drugvaccine_name", "%" + name + "%");
        }
        List<Map<String,Object>> list = drugStoreMapper.getDrugStore(map);

        return new PageInfo<Map<String,Object>>(list);
    }
}
